<template>
  <!-- 维修记录 -->
    <div class="app-container over-scroll">
    <el-row :gutter="20" class="mb20">
      <el-col :span="4"><el-input v-model="req.carCode" type="text" placeholder="请输入车牌号" @change="search"></el-input></el-col>
      <el-col :span="4"><el-input v-model="req.merchant" type="text" placeholder="请输入维修商家" @change="search"></el-input></el-col>
      <el-col :span="6">
        <SelectDateRange :startPlaceholder="`维修开始时间`" :endPlaceholder="`维修结束时间`" :start.sync="req.beginTime" :end.sync="req.endTime" @change="search"></SelectDateRange>
      </el-col>
      <el-col :span="6">
        <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
        <el-button type="success" icon="el-icon-plus" @click="add">新增</el-button>
        <!-- <el-button type="warning" icon="el-icon-download" @click="download">导出</el-button> -->
      </el-col>
    </el-row>

    <el-table :data="list" border style="width: 100%">
      <el-table-column type="index" label="序号" width="60" align="center" show-overflow-tooltip>
        <template slot-scope="{$index}">
          {{$index + 1 + (req.page - 1) * req.pageSize}}
        </template>
      </el-table-column>
      <el-table-column prop="carCode" label="车牌号" align="left" show-overflow-tooltip></el-table-column>
      <el-table-column prop="dateStart" label="开始日期"  align="left" show-overflow-tooltip></el-table-column>
      <el-table-column prop="dateEnd" label="结束日期" align="left" show-overflow-tooltip></el-table-column>
      <el-table-column prop="address" label="维修地点" align="left" show-overflow-tooltip></el-table-column>
      <el-table-column prop="merchant" label="维修商家" align="left" show-overflow-tooltip></el-table-column>
      <el-table-column prop="remark" label="维修内容描述" align="left" show-overflow-tooltip></el-table-column>
      <el-table-column prop="reporterName" label="经办人"  align="left"  show-overflow-tooltip></el-table-column>
      <el-table-column prop="gmtHappen" label="经办日期"  align="left" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pics" label="图片" min-width="120" align="left" show-overflow-tooltip>
        <template slot-scope="{row}">
          <div class="img-item" v-if="row.pics">
            <el-image style="width: 60px; height: 60px;margin-right:8px;" v-for="(img, index) in getImgUrl(row.pics)" :key="index" :src="img" :preview-src-list="getImgUrl(row.pics)"></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="140" align="center">
        <template slot-scope="{ row }">
          <el-button @click="edit(row)" type="text" size="small">编辑</el-button>
          <!-- <el-button @click="detail(row)" type="text" size="small">详情</el-button> -->
          <el-button @click="del(row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="total" :total="total" :page.sync="req.page" :limit.sync="req.pageSize" @pagination="getList"></Pagination>

    <Edit :show.sync="showEdit" :item="currentItem" @confirm="onConfirm"></Edit>
  </div>
</template>
<script>
import Edit from './components/edit.vue'
import {getList, del} from '@/api/carRecord'
export default {
  components: {Edit},
  data() {
    return {
      req: {
        page: 1,
        pageSize: 20,
        type: 2
      },
      total: 0,
      list: [],
      currentItem: null,
      showEdit: false
    }
  },
  mounted() {
    this.search()
  },
  methods: {
    search() {
      this.req.page = 1;
      this.getList()
    },
    async getList() {
      try {
        const res = await getList(this.req);
        this.total = res.total;
        this.list = res.data;
      } catch (error) {}
    },
    onConfirm() {
      this.showEdit = false;
      this.search()
    },
    add() {
      this.currentItem = null;
      this.showEdit = true;
    },
    edit(row) {
      this.currentItem = JSON.parse(JSON.stringify(row))
      this.showEdit = true;
    },
    del(row) {
      this.$modal.confirm('确定删除此条数据吗？').then((res) => {
        del({ id: row.id }).then((res) => {
          this.$message.success('操作成功！')
          this.getList();
        });
      });
    },
  }
}
</script>
